package com.zahb.qadx

import android.content.Context
import android.graphics.Paint
import androidx.core.content.ContextCompat
import com.google.android.material.shape.MaterialShapeDrawable
import com.google.android.material.shape.RoundedCornerTreatment
import com.google.android.material.shape.ShapeAppearanceModel

/**
 * 控件圆角
 * @param Context 上下文
 * @param fillColor 填充颜色
 * @param stroke 描边宽度
 * @param colorRes //描边颜色
 * @param allCorner 四边角度
 * @param topLeftCorner 左上角
 * @param topRightCorner 右上角
 * @param bottomRightCorner 左下角
 * @param bottomLeftCorner 右下角
 */
@JvmOverloads
fun roundedCorners(activity: Context, fillColor: Int, stroke: Float, colorRes: Int, allCorner: Float,
                   topLeftCorner: Float = 0f, topRightCorner: Float = 0f, bottomRightCorner: Float = 0f, bottomLeftCorner: Float = 0f): MaterialShapeDrawable {
    val shapeAppearanceModel2 = ShapeAppearanceModel.builder().apply {
        setAllCorners(RoundedCornerTreatment())
        //setAllCornerSizes(allCorner)
        setTopLeftCornerSize(if (topLeftCorner == 0f) allCorner else topLeftCorner)
        setTopRightCornerSize(if (topRightCorner == 0f) allCorner else topRightCorner)
        setBottomRightCornerSize(if (bottomRightCorner == 0f) allCorner else bottomRightCorner)
        setBottomLeftCornerSize(if (bottomLeftCorner == 0f) allCorner else bottomLeftCorner)
    }.build()
    val drawable: MaterialShapeDrawable = MaterialShapeDrawable(shapeAppearanceModel2).apply {
        setTint(ContextCompat.getColor(activity, fillColor)) //填充颜色
        paintStyle = Paint.Style.FILL_AND_STROKE
        strokeWidth = stroke//描边宽度
        strokeColor = ContextCompat.getColorStateList(activity, colorRes)//描边颜色

    }
    return drawable
}